﻿<?php

$obj=new mysql($config);
if(!empty($_POST)){

   $myfile=$_FILES['myfile'];
   //单、多文件上传（重组数组）
   if(!empty($myfile['tmp_name'][0])){
           $arrlist=array();
           foreach ($myfile['name'] as $k => $v) {
               $arrlist[$k]['name']=$v;
               $arrlist[$k]['type']=$myfile['type'][$k];
               $arrlist[$k]['size']=$myfile['size'][$k];
               $arrlist[$k]['tmp_name']=$myfile['tmp_name'][$k];
               $arrlist[$k]['error']=$myfile['error'][$k];
           }
            foreach ($arrlist as $k => $v) {
                $rootpath=upload($v);
                $thumb=thumb($rootpath);

            }
   }




    $arr=array(
        'title'=>$_POST['title'],
        'content'=>$_POST['content'],
        'cid'=>$_POST['cid'],
        'send'=>$_SESSION['admin']['username'],
        'createtime'=>time(),
        'img'=>isset($rootpath)?$rootpath:'',
        'thumb_img'=>isset($thumb)?$thumb:''
        );

    $num=$obj->insert($arr,'news');
    // $insertid=$obj->getInsertid();
    // $filename="http://localhost/cms/index.php?c=list&a=news-detail&id=".$insertid;
    // $content=file_get_contents($filename);
    // $content=str_replace('index.php','../index.php',$content);
    // file_put_contents('cach/'.$insertid.'.html',$content);
   
    if($num>0){
    echo '<script>alert("添加成功");location.href="index.php?c=news&a=list&mod=admin";</script>';
    }else{
    echo '<script>alert("添加失败,请重新添加");location.href="index.php?c=news&a=add&mod=admin";</script>'; 
    }
}

$sql="select * from `cate`";
$date=$obj->getCondition($sql);

$arr=array();
function getcs($date,$pid,$arr=array(),$level=0){
  foreach ($date as $k => $v) {
         if($v['pid']==$pid){
             $v['level']=$level;
             $arr[]=$v;
             $arr=getcs($date,$v['id'],$arr,$level+2);
         }
         
  }
  return $arr;
}

$select=getcs($date,0,$arr);


require_once (VIEW_PATH.'admin/layout.html');

